﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>商家优惠信息</title>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/ydui.css?v=1.1.4" rel="stylesheet" />
    <script src="../js/ydui.flexible.js"></script>
    <link rel="stylesheet" type="text/css" href="../css/all.css?v=20180302" />
    <style type="text/css">
        .cell-select {
            display: block;
            color: #2A2A2A;
            padding-left: 4rem;
            align-items: center;
        }

        .cell-fileinput {
            position: absolute;
            width: 100%;
            z-index: 9999999;
            width: 70%;
            height: 1rem;
            right: 0;
            opacity: 0;
        }
        .m-cell:after{border:none;}
    </style>
</head>
<body ms-controller="youhuiview" class="ms-controller">
    <div class="page-group">
        <div class="page page-current" id="rounter">
            <div class="g-flexview">
                <header class="m-navbar">
                    <a href="vd_index.html" class="navbar-item"><i class="back-ico"></i></a>
                    <div class="navbar-center"><span class="navbar-title">商家优惠信息</span></div>
                </header>
                <div class="g-scrollview">
                    <div ms-visible="!@IsAdd">
                        <div class="m-cell" ms-for="el in @ListData">
                            <div class="cell-item">
                                <div class="cell-left">消费满{{el.FullPrice}}元</div>
                                <div class="cell-right">可使用{{el.DisPrice}}元万能券</div>
                            </div>
                            <div class="cell-item">
                                <div class="cell-left"></div>
                                <div class="cell-right"><a ms-on-tap="@Del(el)"><span class="iconfont icon-delete1"></span>删除</a></div>
                            </div>
                        </div>
                    </div>

                    <div ms-visible="@IsAdd">
                        <div class="m-cell">
                            <div class="cell-item">
                                <div class="cell-left">消费满(元)</div>
                                <div class="cell-right" style="padding-left:5px;">
                                    <input type="number" class="cell-input" placeholder="请输入消费金额" ms-duplex="@ModelData.FullPrice" />
                                </div>
                            </div>
                            <div class="cell-item">
                                <div class="cell-left">可使用万能券(元)</div>
                                <div class="cell-right" style="padding-left:5px;">
                                    <input type="number" class="cell-input" placeholder="请输入万能券金额" ms-duplex="@ModelData.DisPrice" />
                                </div>
                            </div>
                        </div>
                        <a class="btn  btn-primary" style="width:95%;margin:0.2rem;color:#fff;" ms-on-tap="@Save()">
                            保存
                        </a>
                        <a class="btn  btn-primary" style="width:95%;margin:0.2rem;color:#fff;background-color:#d3cfcf;" ms-on-tap="@IsAdd=!@IsAdd">
                            返回
                        </a>
                    </div>
                </div>

                <a href="javascript:void(0)" class="btn  btn-primary" style="width:95%;margin:0.2rem;color:#fff;position:relative;z-index:100;" ms-on-tap="@Add()" ms-visible="!@IsAdd">
                    添加优惠
                </a>
            </div>
        </div>

    </div>
    <script src="https://cdn.bootcss.com/jquery/2.2.0/jquery.min.js"></script>
    <script src="../js/ydui.js"></script>
    <script src="../js/avalon.mobile.min.js"></script>
    <script src="../js/ComFunJS.js?v=20180331"></script>
    <script>

        var model = avalon.define({
            $id: "youhuiview",
            ListData: [],
            GetListData: function () {
                $.getJSON("/api/user/vd/yh", function (r) {
                    if (r.error == "") {
                        model.ListData = r.result;
                    }
                })

            },
            IsAdd:false,
            Del: function (el) {
                YDUI.dialog.confirm("", "确定要删除吗？", function () {

                    $.getJSON("/api/user/vd/yhdel/" + el.ID, function (r) {
                        if (r.error == "") {
                            model.ListData.remove(el);
                        }
                    })
                })
            },
            Add: function () {
                model.IsAdd = true;
            },
            ModelData: { "ID": 0, "FullPrice": "", "DisPrice": "" },
            Save: function () {

                if (!model.ModelData.FullPrice || !model.ModelData.DisPrice) {
                    YDUI.dialog.toast("请输入消费金额和万能券金额", 'none', 1000);
                    return;
                }

                YDUI.dialog.confirm("", "确定要保存吗？", function () {

                    $.post("/api/user/vd/yhadd", model.ModelData.$model, function (r) {
                        if (r.error == "") {
                            YDUI.dialog.toast("保存成功", 'none', 2000, function () {
                                //window.location.href = "vd_yh.html?r=" + Math.random();
                                model.ModelData.FullPrice = "";
                                model.ModelData.DisPrice = "";
                                model.ListData.push(r.result);
                                model.IsAdd = false;
                            });
                        } else {
                            YDUI.dialog.toast(r.error, 'none', 2000);
                        }

                    })
                })

            }

        });
        avalon.ready(function () {
            if (ComFunJS.isLogin(true)) {
                model.GetListData();
            }
        })

    </script>
</body>

</html>
